package com.emeraldparser.util;

import com.google.common.base.Objects;

public final class Pair<A, B> {

	private final A a;
	private final B b;

	private Pair(A a, B b) {
		this.a = a;
		this.b = b;
	}

	public static <A, B> Pair<A, B> create(A a, B b) {
		return new Pair<A, B>(a, b);
	}

	public A a() {
		return a;
	}

	public B b() {
		return b;
	}

	@Override
	public String toString() {
		return "(" + a + ", " + b + ")";
	}

	@Override
	public int hashCode() {
		return Objects.hashCode(a, b);
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		
		if (obj == null) {
			return false;
		}
		
		if (getClass() != obj.getClass()) {
			return false;
		}
		
		Pair<?, ?> other = (Pair<?, ?>) obj;
		
		return Objects.equal(a, other.a)
		    && Objects.equal(b, other.b);
	}

}
